<template>
  <div class="app-container">
    <div class="filter-container">
      <h4>发送目的地
        <el-checkbox v-model="allchecked" style="margin-left:20px">全选</el-checkbox>
      </h4>
      <el-select v-model="listQuery.selectvalue" filterable multiple placeholder="请选择发送给谁" style="width:400px;"  >
        <el-option
          v-for="item in userList"
          :key="item.id"
          :label="item.user"
          :value="item.id"

        >
        </el-option>
      </el-select>
      <h4>标题</h4>
      <el-input
        v-model="listQuery.title"
        size="small"
        placeholder="请输入消息标题"
        clearable
        style="width:400px;"
        class="filter-item"
      />
      <h4>内容</h4>

      <el-input type="textarea" v-model="listQuery.desc" style="width:400px;"></el-input>
      <div style="margin-top:20px;display: flex;justify-content: space-between;width:400px">

        <el-button
          type="primary"
          icon="el-icon-search"
          style="width: 200px"
          @click="send"
        >
          发送
        </el-button>
        <el-button
          type="info"
          style="width: 200px"
          icon="el-icon-refresh"
          @click="refresh"
        >
          重置
        </el-button>
      </div>
    </div>


  </div>
</template>

<script>
import { getALLadmincp ,doSendMessage } from '@/api/user'

export default {
  data() {
    return {
      listQuery: {
        selectvalue: [],
        title: ''
      },
      allchecked: true,
      userList: []
    }
  },
  watch: {
    allchecked(v) {
      if (v) {
        this.allchange()
      } else {
        this.$set(this.listQuery, 'selectvalue', [])
      }
    }
  },
  created() {
    this.getAdmin()
  },
  methods: {
    allchange(v) {
      let allAry = []
      for (let i = 0; i < this.userList.length; i++) {
        allAry.push(this.userList[i].id)
      }
      this.$set(this.listQuery, 'selectvalue', allAry)
    },
    refresh() {
      this.listQuery = {
        selectvalue: [],
        title: '',
        desc: ''
      }
    },
    send() {
      doSendMessage(this.listQuery).then(r=>{
        this.refresh();
        this.$message({
          message: '发送成功',
          type: 'success'
        })
      })
    },
    getAdmin() {
      getALLadmincp().then(r => {
        let userData = r.data
        this.userList = userData
        this.allchange()
      })
    }
  }
}
</script>
<style lang="less" scoped>
/deep/ .el-textarea__inner {
  height: 180px;
}

/deep/ .el-input__inner {
  height: 48px;
}
</style>
